/**
 * 
 */
package com.playball.lottery.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.util.Log;

/**
 * @author sunfanglei
 * @date 2014年2月14日
 */
public class JCZQUtil {
	
	/**
	 * 将竞彩足球比分sp格式从31种结果一起一组，主胜，平，主负中间加分隔符，以便拆分成3组，主胜，平，主负
	 * 
	 * @param str_sp
	 *            
	 * @return 
	 */
	public static String changeCBF3(String str_sp) {
//		 Log.v("JCZQUtil ", "str_sp= "+str_sp.toString());
		String[] SpCBFs=str_sp.split("\\|");
		List<String> list =new ArrayList<String>();
		list=Arrays.asList(SpCBFs);
//		System.out.println("changeCBF3 list= " + list.toString());
//		System.out.println("changeCBF3 list.size()= " + list.size());
		List<String> lists =new ArrayList<String>();
		List<String> listp =new ArrayList<String>();
		List<String> listf =new ArrayList<String>();
		for(int i=0;i<list.size();i++){
			if(i<13){
				lists.add(list.get(i));
			}
			if(i>=13&&i<18){
				listp.add(list.get(i));
			}
			if(i>=18&&i<31){
				listf.add(list.get(i));
			}
		}
//		System.out.println("changeCBF3 lists= " + lists.toString());
//		System.out.println("changeCBF3 listp= " + listp.toString());
//		System.out.println("changeCBF3 listf= " + listf.toString());
		String sPBFS;
		String sPBFP;
		String sPBFF;
		//list转化为string
		StringBuffer sbs = new StringBuffer();
		for (int i = 0; i < lists.size(); i++) {
			sbs.append(lists.get(i) + "|"); // ,
		}
		sPBFS = sbs.toString();
		if(sPBFS.endsWith("|")){
			sPBFS=sPBFS.substring(0,sPBFS.length()-1);
		}
//		System.out.println("changeCBF3 sPBFS= " + sPBFS);
		
		StringBuffer sbp = new StringBuffer();
		for (int i = 0; i < listp.size(); i++) {
			sbp.append(listp.get(i) + "|"); // ,
		}
		sPBFP = sbp.toString();
		if(sPBFP.endsWith("|")){
			sPBFP=sPBFP.substring(0,sPBFP.length()-1);
		}
//		System.out.println("changeCBF3sPBFP= " + sPBFP);
		
		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < listf.size(); i++) {
			sbf.append(listf.get(i) + "|"); // ,
		}
		sPBFF = sbf.toString();
		if(sPBFF.endsWith("|")){
			sPBFF=sPBFF.substring(0,sPBFF.length()-1);
		}
//		System.out.println("changeCBF3 sPBFF= " + sPBFF);
		return sPBFS+","+sPBFP+","+sPBFF;
	}

	/**
	 * 金山新接口，将竞彩足球比分sp格式从31种结果一起一组，主胜，平，主负中间加分隔符，以便拆分成3组，主胜，平，主负
	 * 
	 * @param str_sp
	 *            比分的顺序是这样的['负其他', '平其他', '胜其他', '0:0', '0:1', '0:2', '0:3',
	 *            '0:4', '0:5', '1:0', '1:1', '1:2', '1:3', '1:4', '1:5', '2:0',
	 *            '2:1', '2:2', '2:3', '2:4', '2:5', '3:0', '3:1', '3:2', '3:3',
	 *            '4:0', '4:1', '4:2', '5:0', '5:1', '5:2']; str_sp=
	 *            70.00,300.0,
	 *            80.00,9.00,7.00,10.00,22.00,50.00,200.0,7.50,5.70,8.50
	 *            ,19.00,40.00
	 *            ,150.0,12.00,8.50,12.00,27.00,80.00,250.0,24.00,20.00
	 *            ,28.00,50.00,70.00,60.00,80.00,250.0,200.0,250.0,1,1
	 * 
	 * @return 网站一致顺序
	 */
	public static String jschangeCBF3(String str_sp) {
		// Log.v("JCZQUtil ", "str_sp= "+str_sp.toString());
		String[] SpCBFs = str_sp.split(",");
		// 去掉最后面的,1,1
		String sPBFS = "";
		String sPBFP = "";
		String sPBFF = "";
		if (SpCBFs.length >= 30) {
			// "1:0", "2:0", "2:1", "3:0", "3:1", "3:2", "4:0", "4:1", "4:2",
			// "5:0", "5:1", "5:2", "胜其他"
			sPBFS = SpCBFs[9] + "," + SpCBFs[15] + "," + SpCBFs[16] + "," + SpCBFs[21] + "," + SpCBFs[22] + "," + SpCBFs[23] + "," + SpCBFs[25] + ","
					+ SpCBFs[26] + "," + SpCBFs[27] + "," + SpCBFs[28] + "," + SpCBFs[29] + "," + SpCBFs[30] + "," + SpCBFs[2];
			// "0:0", "1:1", "2:2", "3:3", "平其他"
			sPBFP = SpCBFs[3] + "," + SpCBFs[10] + "," + SpCBFs[17] + "," + SpCBFs[24] + "," + SpCBFs[1];
			// "0:1", "0:2", "1:2", "0:3", "1:3", "2:3", "0:4", "1:4", "2:4",
			// "0:5", "1:5", "2:5", "负其他"
			sPBFF = SpCBFs[4] + "," + SpCBFs[5] + "," + SpCBFs[11] + "," + SpCBFs[6] + "," + SpCBFs[12] + "," + SpCBFs[18] + "," + SpCBFs[7] + "," + SpCBFs[13]
					+ "," + SpCBFs[19] + "," + SpCBFs[8] + "," + SpCBFs[14] + "," + SpCBFs[20] + "," + SpCBFs[0];
		} else {
//			System.out.println("JCZQUtil jschangeCBF3 比分数据格式错误  SpCBFs.length= " + SpCBFs.length);
		}

		return sPBFS + "|" + sPBFP + "|" + sPBFF;
	}

	/**
	 * 将金山新接口比分数据格式转换成老线上比分数据格式，将竞彩足球比分sp格式从杂乱无序转换成31种结果一起一组，主胜，平，主负中间加分隔符|
	 * 
	 * @param str_sp
	 *            比分的顺序是这样的['负其他', '平其他', '胜其他', '0:0', '0:1', '0:2', '0:3',
	 *            '0:4', '0:5', '1:0', '1:1', '1:2', '1:3', '1:4', '1:5', '2:0',
	 *            '2:1', '2:2', '2:3', '2:4', '2:5', '3:0', '3:1', '3:2', '3:3',
	 *            '4:0', '4:1', '4:2', '5:0', '5:1', '5:2']; str_sp=
	 *            70.00,300.0,
	 *            80.00,9.00,7.00,10.00,22.00,50.00,200.0,7.50,5.70,8.50
	 *            ,19.00,40.00
	 *            ,150.0,12.00,8.50,12.00,27.00,80.00,250.0,24.00,20.00
	 *            ,28.00,50.00,70.00,60.00,80.00,250.0,200.0,250.0,1,1
	 * 
	 * @return 网站一致顺序 主胜|平|主负
	 */
	public static String jschangeCBFold(String str_sp) {
		// Log.v("JCZQUtil ", "str_sp= "+str_sp.toString());
		String[] SpCBFs = str_sp.split(",");
		// 去掉最后面的,1,1
		String sPBFS = "";
		String sPBFP = "";
		String sPBFF = "";
		if (SpCBFs.length >= 30) {
			// "1:0", "2:0", "2:1", "3:0", "3:1", "3:2", "4:0", "4:1", "4:2",
			// "5:0", "5:1", "5:2", "胜其他"
			sPBFS = SpCBFs[9] + "|" + SpCBFs[15] + "|" + SpCBFs[16] + "|" + SpCBFs[21] + "|" + SpCBFs[22] + "|" + SpCBFs[23] + "|" + SpCBFs[25] + "|"
					+ SpCBFs[26] + "|" + SpCBFs[27] + "|" + SpCBFs[28] + "|" + SpCBFs[29] + "|" + SpCBFs[30] + "|" + SpCBFs[2];
			// "0:0", "1:1", "2:2", "3:3", "平其他"
			sPBFP = SpCBFs[3] + "|" + SpCBFs[10] + "|" + SpCBFs[17] + "|" + SpCBFs[24] + "|" + SpCBFs[1];
			// "0:1", "0:2", "1:2", "0:3", "1:3", "2:3", "0:4", "1:4", "2:4",
			// "0:5", "1:5", "2:5", "负其他"
			sPBFF = SpCBFs[4] + "|" + SpCBFs[5] + "|" + SpCBFs[11] + "|" + SpCBFs[6] + "|" + SpCBFs[12] + "|" + SpCBFs[18] + "|" + SpCBFs[7] + "|" + SpCBFs[13]
					+ "|" + SpCBFs[19] + "|" + SpCBFs[8] + "|" + SpCBFs[14] + "|" + SpCBFs[20] + "|" + SpCBFs[0];
		} else {
//			System.out.println("JCZQUtil jschangeCBFold 比分数据格式错误  SpCBFs.length= " + SpCBFs.length);
		}

		return sPBFS + "|" + sPBFP + "|" + sPBFF;
	}

	/**
	 * 将北京单场比分sp格式从25种结果一起一组，主胜，平，主负中间加分隔符，以便拆分成3组，主胜，平，主负
	 * 
	 * @param str_sp
	 * 
	 * @return
	 */
	public static String changeBDBF3(String str_sp) {
		// Log.v("JCZQUtil ", "str_sp= "+str_sp.toString());
		String[] SpCBFs = str_sp.split("\\|");
		List<String> list = new ArrayList<String>();
		list = Arrays.asList(SpCBFs);
		List<String> lists = new ArrayList<String>();
		List<String> listp = new ArrayList<String>();
		List<String> listf = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++) {
			if (i < 10) {
				lists.add(list.get(i));
			}
			if (i >= 10 && i < 15) {
				listp.add(list.get(i));
			}
			if (i >= 15 && i < 25) {
				listf.add(list.get(i));
			}
		}
		String sPBFS;
		String sPBFP;
		String sPBFF;
		// list转化为string
		StringBuffer sbs = new StringBuffer();
		for (int i = 0; i < lists.size(); i++) {
			sbs.append(lists.get(i) + "|"); // ,
		}
		sPBFS = sbs.toString();
		if (sPBFS.endsWith("|")) {
			sPBFS = sPBFS.substring(0, sPBFS.length() - 1);
		}

		StringBuffer sbp = new StringBuffer();
		for (int i = 0; i < listp.size(); i++) {
			sbp.append(listp.get(i) + "|"); // ,
		}
		sPBFP = sbp.toString();
		if (sPBFP.endsWith("|")) {
			sPBFP = sPBFP.substring(0, sPBFP.length() - 1);
		}

		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < listf.size(); i++) {
			sbf.append(listf.get(i) + "|"); // ,
		}
		sPBFF = sbf.toString();
		if (sPBFF.endsWith("|")) {
			sPBFF = sPBFF.substring(0, sPBFF.length() - 1);
		}
		return sPBFS + "," + sPBFP + "," + sPBFF;
	}

	/**
	 * 将竞彩篮球胜分差网络数据sp格式从12种结果一起一组，主胜，主负中间加分隔符，以便拆分成2组，主胜，主负
	 * 
	 * @param str_sp
	 * 
	 * @return
	 */
	public static String changeSFC2(String str_sp) {
		String[] Spsfcs = str_sp.split("\\|");
		List<String> list = new ArrayList<String>();
		list = Arrays.asList(Spsfcs);
		List<String> lists = new ArrayList<String>();
		List<String> listf = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++) {
			if (i < 6) {
				listf.add(list.get(i));
			}
			if (i >= 6 && i < 12) {// "SpSFC": 胜分差sp，依次客胜、主胜六个区间,
				lists.add(list.get(i));
			}
		}
		String sPSFCS;
		String sPSFCF;
		// list转化为string
		StringBuffer sbs = new StringBuffer();
		for (int i = 0; i < lists.size(); i++) {
			sbs.append(lists.get(i) + "|"); // ,
		}
		sPSFCS = sbs.toString();
		if (sPSFCS.endsWith("|")) {
			sPSFCS = sPSFCS.substring(0, sPSFCS.length() - 1);
		}

		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < listf.size(); i++) {
			sbf.append(listf.get(i) + "|"); // ,
		}
		sPSFCF = sbf.toString();
		if (sPSFCF.endsWith("|")) {
			sPSFCF = sPSFCF.substring(0, sPSFCF.length() - 1);
		}
		return sPSFCS + "," + sPSFCF;
	}

	/**
	 * 将金山新接口竞彩篮球胜分差网络数据sp格式从12种结果一起一组，主胜，主负中间加分隔符，以便拆分成2组，主胜，主负
	 * 
	 * @param str_sp
	 *            "SPSFC":
	 *            "9.75,16.00,35.00,70.00,200.0,250.0,4.85,3.25,3.70,4.50,6.80,7.75,1"
	 *            ,
	 * 
	 * @return "SpSFC":
	 *         "9.15|15.00|30.00|72.00|170.0|210.0|5.65|3.50|3.60|4.45|6.60|6.70"
	 *         ,
	 */
	public static String jschangeSFC2(String str_sp) {
		// Log.v("JCZQUtil ", "str_sp= "+str_sp.toString());
		str_sp = str_sp.replaceAll(",", "\\|");
		Log.v("JCZQUtil ", "jschangeSFC2 str_sp= " + str_sp.toString());
		String[] Spsfcs = str_sp.split("\\|");
		List<String> list = new ArrayList<String>();
		list = Arrays.asList(Spsfcs);
		List<String> lists = new ArrayList<String>();
		List<String> listf = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++) {
			if (i < 6) {
				listf.add(list.get(i));
			}
			if (i >= 6 && i < 12) {// "SpSFC": 胜分差sp，依次客胜、主胜六个区间,
				lists.add(list.get(i));
			}
		}
		String sPSFCS;
		String sPSFCF;
		// list转化为string
		StringBuffer sbs = new StringBuffer();
		for (int i = 0; i < lists.size(); i++) {
			sbs.append(lists.get(i) + "|"); // ,
		}
		sPSFCS = sbs.toString();
		if (sPSFCS.endsWith("|")) {
			sPSFCS = sPSFCS.substring(0, sPSFCS.length() - 1);
		}

		StringBuffer sbf = new StringBuffer();
		for (int i = 0; i < listf.size(); i++) {
			sbf.append(listf.get(i) + "|"); // ,
		}
		sPSFCF = sbf.toString();
		if (sPSFCF.endsWith("|")) {
			sPSFCF = sPSFCF.substring(0, sPSFCF.length() - 1);
		}
		return sPSFCS + "," + sPSFCF;
	}

}
